/**
 * displays the Dialog for creating or modifying an ItemClass
 * @author zulianp@lu.unisi.ch & remo.lemma@lu.unisi.ch
 */

package ch.unisi.inf.projects.java.uom.gui.commands;

import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
import javax.swing.KeyStroke;

import ch.unisi.inf.projects.java.uom.gui.UOMImages;
import ch.unisi.inf.projects.java.uom.elements.ItemClass;
import ch.unisi.inf.projects.java.uom.gui.itemclasseditor.UOMItemClassEditorDialog;

public final class ItemClassGUICreateCommand extends IconedCommand
{
	/** We are not going to serialize this class atm */
	private static final long serialVersionUID = -1L;
	
	private final ItemClass itemClass;
	
    public ItemClassGUICreateCommand()
    {
    	super("", "Create a new Category with personalized fields", UOMImages.CREATE.getFileName());
        putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_N, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
        this.itemClass = null;
    }
    
    public ItemClassGUICreateCommand (final ItemClass itemClass)
    {
    	super("Modify Category", "Modifies an existing Category", null);
    	this.itemClass = itemClass;
    }
    
    public void actionPerformed(final ActionEvent ev)
    {
    	final UOMItemClassEditorDialog iCEDialog;
    	if (itemClass == null)
    		iCEDialog = new UOMItemClassEditorDialog("Create new category", null); //parent for modal
    	else
    		iCEDialog = new UOMItemClassEditorDialog("Modify Category", itemClass); //parent
    	iCEDialog.setVisible(true);
    	iCEDialog.repaint();
    }
}
 